package han.chensing.latos.maker;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.utils.viewport.FitViewport;
import han.chensing.latos.maker.container.WindowsContainer;
import han.chensing.latos.maker.screen.MainScreen;
import han.chensing.latos.maker.screen.WelcomeScreen;
import space.earlygrey.shapedrawer.ShapeDrawer;

public class GameMain extends ApplicationAdapter {

	private static GameMain instance;

	public static ShapeDrawer shapeDrawer;

	WelcomeScreen welcomeScreen;
	MainScreen mainScreen;

	boolean loading=true;

	@Override
	public void create () {
		instance=this;
		V.camera=new OrthographicCamera();
		V.initSize();
		V.viewport=new FitViewport(V.WIDTH,V.HEIGHT, V.camera);
		V.container=new WindowsContainer(V.viewport);
		welcomeScreen=new WelcomeScreen();
		mainScreen=new MainScreen();
	}

	@Override
	public void render () {
		super.render();
		V.camera.update();
		float deltaTime = Gdx.graphics.getDeltaTime();
		if (loading)welcomeScreen.render(deltaTime);
		else mainScreen.render(deltaTime);
	}

	@Override
	public void resize(int width, int height) {
		super.resize(width, height);
		V.container.onResize(width,height);
	}

	@Override
	public void dispose () {
		super.dispose();
		welcomeScreen.dispose();
		mainScreen.dispose();
	}

	public void loadingComplete(){
		mainScreen.init();
		loading=false;
	}

	public static GameMain getInstance() {
		return instance;
	}
}
